package 聊天室;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class user1 {
    public static void main(String[] args) throws IOException {
        //创建socket对象，链接服务端

        //从通道中写入数据
        Scanner s = new Scanner(System.in);
        String user = "李华";
        while (true) {
            Socket socket = new Socket("127.0.0.1",8888);
            System.out.println("请输入您要说的话：");
            String input = s.nextLine();
            OutputStream out = socket.getOutputStream();
            out.write((user+":"+input).getBytes());
            //释放资源
            out.close();
            socket.close();
            //-----------------------------
//            Socket socket1 = new Socket("127.0.0.1",8888);
//            StringBuffer sb = new StringBuffer();
//            InputStream is = socket1.getInputStream();
//            InputStreamReader isr = new InputStreamReader(is);
//            int b;
//            while ((b = isr.read()) != -1){
//                sb.append((char) b);
//            }
//            System.out.println(sb);
//            //释放资源
//            isr.close();
//            socket.close();
        }

    }
}
